var express = require('express');
var router = express.Router();
var query = require('./Database');
/* GET home page. */
router.get('/', function(req, res, next) {
    res.render('ProMyLetter', {});
});
router.post('/letter',async (req,res)=>{
    // console.log(req.body);
    let list = req.body;
    let rows = await query("select * from letter where userid = "+ list.userid + " and letterstate = 1 or letterstate = 2");
    console.log('+++++++++++++++++++');
    console.log(rows);
    console.log('+++++++++++++++++++');
    let data1 = [{code:100},rows];
    res.send(data1);
});
router.post('/checkletter',async (req,res)=>{
    console.log("--------------");
    console.log(req.body);
    let list = req.body;
    let rows = await query("update letter set letterstate = 2 where id = "+ list.letterid);
    let data2 = {code:100};
    res.send(data2);
});
router.post('/deleteletter',async (req,res)=>{
    console.log("--------------");
    console.log(req.body);
    let list = req.body;
    let rows = await query("update letter set letterstate = 3 where id = "+ list.letterid);
    let data3 = {code:100};
    res.send(data3);
});
module.exports = router;